# 打开文件
# f = open("b.txt","w",encoding="utf-8") # 如果不存在该文件，则会新建一个
f = open("b.txt","a",encoding="utf-8") # 如果不存在该文件，则会新建一个

# 写数据
# f.write("静夜思\n床前明月光\n疑是地上霜")
f.write("\n举头望明月\n低头思故乡")
# 关闭文件
f.close()

# with open() as 变量名 打开文件 系统会自动关闭文件
with open("d:\\c.txt","w",encoding="utf-8") as file:
    file.write("我是个测试文件")


# 路径分隔符：
#     window系统：\
#     linux系统：/
# 路径字符串：
#     r"D:\课程\02.xinqidian-python-10天\作业\day05"
#     "D:\\课程\\02.xinqidian-python-10天\\作业\\day05"
#     "D:/课程/02.xinqidian-python-10天/作业/day05"
# 绝对路径：带盘符的全路径
# 相对路径：相对该文件所在的路径 ../ 父路径

with open("../d.txt","w",encoding="utf-8") as file:
    file.write("我是个测试文件")